package week4;
import java.util.Scanner;
/**
 * Created by dell on 2017/3/14.
 */
public class ApproximateCalculation {
    public static void main(String[] args){
        int n;
        float sum = (float) 0;
        int sign = -1;
        Scanner scanner = new Scanner(System.in);
        System.out.print("请输入n的值：" );
        n = scanner.nextInt();
        for(int i = 1; i <= n; i ++){
            sign *= -1;
            sum += (float)(sign * (1.0/(2*i-1)));
        }
        sum *= (float) 4.0;
        System.out.println("π的近似值为：" + sum);
    }
}
